function initGrid(grid) {

    var columns=[
        { field: "id", title: "id", align: "left",hidden:"true",halign: "center", sortable: false, resizable: true, width: 250},
        { field: "shareholderName", title: "股东名称", align: "center",halign: "center", sortable: false, resizable: true, width: 250},
        { field: "papersType", title: "证件类型",hidden:"true",align: "center",halign: "center", sortable: false, resizable: true, width: 100},
        { field: "papersName", title: "证件类型", align: "center",halign: "center", sortable: false, resizable: true, width: 100},
        { field: "papersCode", title: "证件号码", align: "center",halign: "center", sortable: false, resizable: true, width: 150},
        { field: "investmentRatio", title: "投资比例", align: "center",halign: "center", sortable: false, resizable: true, width: 150},
        { field: "incomeMoney", title: "当年（决议日）分配的股息、红利等权益性投资收益金额", align: "center",halign: "center", sortable: false, resizable: true, width: 120},
        { field: "registeredAddress", title: "国籍（注册地址）", align: "center",halign: "center", sortable: false, resizable: true, width: 150}
    ];

    var queryParams=new Object();
    var id = $("#id").val();
    var url="/system/shareholder/getPage?id="+id;
    initPageGrid(grid, queryParams, url,columns,"#tb");
    getPage(grid,queryParams,url);

}

function BatchAdd(){
    layer.open({
        type: 2,
        title: ['股东信息 - 修改','background: #38acff;'],
        shadeClose: false,
        shade: 0.3,
        area: ['700px', '260px'],
        content: '/system/shareholder/toAdd',
        end: function callback() {
            $('#shareholder').datagrid('insertRow',{
                index:0 ,  // 索引从0开始
                row: {
                    shareholderName: params.shareholderName,
                    papersType: params.papersType,
                    papersCode: params.papersCode,
                    investmentRatio: params.investmentRatio,
                    incomeMoney:params.incomeMoney,
                    registeredAddress:params.registeredAddress
                }
            });

            $.parser.parse();
        }
    });
}
function Edit(){
    var row =  $('#shareholder').datagrid('getSelected');

    if(row==null){
        $.messager.alert("提示操作", "请选择修改项",function(){});
        return;
    }

    layer.open({
        type: 2,
        title: ['股东信息 - 修改','background: #38acff;'],
        shadeClose: false,
        shade: 0.3,
        area: ['700px', '260px'],
        content: '/system/shareholder/toAdd',
        success: function(layero, index){
            var body = layer.getChildFrame("body",index);
            var iframeWin = window[layero.find('iframe')[0]['name']];
            if(iframeWin != null){
                iframeWin.setDefaultData($('#shareholder').datagrid('getSelected'));
            }
            var rowIndex = $('#shareholder').datagrid('getRowIndex', row);
            $('#shareholder').datagrid('deleteRow', rowIndex);
        },
        end: function callback() {
            $('#shareholder').datagrid('insertRow',{
                index:0 ,  // 索引从0开始
                row: {
                    shareholderName: params.shareholderName,
                    papersType: params.papersType,
                    papersCode: params.papersCode,
                    investmentRatio: params.investmentRatio,
                    incomeMoney:params.incomeMoney,
                    registeredAddress:params.registeredAddress
                }
            });

            $.parser.parse();
        }
    });
}
function Del() {
    var row =  $('#shareholder').datagrid('getSelected');
    var rowIndex = $('#shareholder').datagrid('getRowIndex', row);
    $('#shareholder').datagrid('deleteRow', rowIndex);
}
function btnBatchAdd() {

    layer.open({
        type: 2,
        title: ['股东信息 - 新增','background: #38acff;'],
        shadeClose: false,
        shade: 0.3,
        area: ['700px', '260px'],
        content: '/system/shareholder/toAdd',
        end: function callback() {
            var returnValue = new Object();
            returnValue.shareholderName = params.shareholderName;
            returnValue.papersType = params.papersType;
            returnValue.papersCode = params.papersCode;
            returnValue.investmentRatio = params.investmentRatio;
            returnValue.incomeMoney = params.incomeMoney;
            returnValue.registeredAddress = params.registeredAddress;
            returnValue.taxpayersinfo = $("#id").val();
            returnValue.delmark = "0";
            $.ajax({
                type:"POST",
                url:'/system/shareholder/saveShareholder',
                data : returnValue,
                dataType:"json",
                success:function(data){

                    if(data.code != '0000'){
                        $.messager.alert("提示操作", data.msg,function(){});
                    } else {
                        $.messager.alert("提示操作", "添加成功",function(){});
                    }
                    init();
                    //closeLayer();
                },
                error: function() {
                    alert('保存数据时发生错误！');
                }
            });
            $.parser.parse();
        }
    });


}
function btnEdit(){
    var id =  $('#shareholder').datagrid('getSelected').id;
    layer.open({
        type: 2,
        title: ['股东信息 - 修改','background: #38acff;'],
        shadeClose: false,
        shade: 0.3,
        area: ['700px', '260px'],
        content: '/system/shareholder/toUpdate?id='+id
    });
}
function btnDel() {
    var returnValue = new Object();
    var id =  $('#shareholder').datagrid('getSelected').id;
    returnValue.id = id;
    returnValue.delmark = "1";
    $.ajax({
        type:"POST",
        url:'/system/shareholder/update',
        data : returnValue,
        dataType:"json",
        success:function(data){

            if(data.code != '0000'){
                $.messager.alert("提示操作", data.msg,function(){});
            } else {
                $.messager.alert("提示操作", "删除成功",function(){});
            }
            init();
            //closeLayer();
        },
        error: function() {
            alert('保存数据时发生错误！');
        }
    });
}

